<?php
/**
 * Created by PhpStorm.
 * User: zhangbing
 * Date: 2017/3/16 0016
 * Time: 17:27
 */
namespace app\admin\controller;
use app\models\Models;

class Order extends Check{
    /**
     * 订单列表
     * @return \think\response\View
     */
    public function orderList(){
        $get = input('param.');
        $order = new Models('order');
        $type  = new Models('orderType');
        // 条件查询
        $search = search($get,'a.order_no,b.nickname,c.name','a.create_time','a.status');
        $where  = $search['condition'];
        // 商家登录
        $group_arr = self::getGroup();
        if($group_arr['group_id'] == Models::GROUP_BUSINESS){
            $where .= ' and a.bid = '.$group_arr['id'];
            $flag = true;
        }
        // 支付方式查询
        if($get['pay_method']){
            $where .= ' and a.pay_method = '.$get['pay_method'];
            $search['display']['pay_method'] = $get['pay_method'];
        }
        // 桌号跳转查询列表
        if($get['table_id']){
            $where .= ' and a.table_id = '.$get['table_id'];
            $search['display']['table_id'] = $get['table_id'];
        }
        $join   = [
            ['user b','a.uid = b.id','left'],
            ['business c','a.bid = c.id','left'],
            ['orderType d','a.type_id = d.id','left'],
            ['voucher e','a.voucher_id = e.id','left'],
            ['table f','a.table_id = f.id','left'],
        ];
        $where .= ' and a.type_id != '.Models::ORDER_TYPE_RECHARGE;
        $field  = "a.*,b.nickname,c.name,d.name type_name,e.price,e.goods,e.type_id voucher,f.name table_name";
        $list = $order->_page($where,$field,'a.id desc',$join,$get['page'],15,$get);
        $order_type = $type->_select(['status'=>Models::STATUS_ON]);
        return view('orderList',['list'=>$list->items(),'page'=>$list->render(),'display'=>$search['display'],'type'=>$order_type,'flag'=>$flag]);
    }

    /**
     * 订单详情
     * @return \think\response\View
     */
    public function orderShow(){
        $get = input('param.');
        $order = new Models('order');
        $join = [
            ['order_goods b','a.id = b.oid','left'],
            ['goods c','b.gid = c.id','left'],
        ];
        $field = 'b.qty,c.name,c.price,c.descrip,c.image,c.goods_no';
        $list  = $order->joinMany($join,['a.id'=>$get['id']],$field);
        $info  = $order->joinOne([['voucher b','a.voucher_id = b.id','left']],['a.id'=>$get['id']],'a.*,b.type_id voucher_type,b.price voucher_price,b.goods voucher_goods');
        $config = self::getConfig();
        $info['pre'] = $config['http'].$_SERVER['HTTP_HOST']. DS .'uploads'. DS .'goods'. DS;
        return view('orderShow',['info'=>$info,'list'=>$list]);
    }
}